using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.IO;
using System.Collections.Generic;
using System.Net;

namespace PluginTemplate
{
	/// <summary>
	/// Summary description for ctlMain.
	/// </summary>
	public class ctlMain : System.Windows.Forms.UserControl
    {
        private ListViewColumnSorter lvwColumnSorter;
        private List<string> lstFavoriteCodes;
        private string sListFavoritePath;
        private WebClient webClient;
        private int iMode;
        private string currency;
        private int nMarket;
        private string[] MarketNames;
        private string[] PriceBoardServices;
        private Timer timerUpdatePriceBoard;
        private ComboBox cbMarkets;
        private Button btnUpdate;
        private IContainer components;

		public ctlMain()
		{
			// This call is required by the Windows.Forms Form Designer.
			InitializeComponent();

			// TODO: Add any initialization after the InitializeComponent call

		}

		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Component Designer generated code
		/// <summary> 
		/// Required method for Designer support - do not modify 
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            this.components = new System.ComponentModel.Container();
            this.timerUpdatePriceBoard = new System.Windows.Forms.Timer(this.components);
            this.cbMarkets = new System.Windows.Forms.ComboBox();
            this.btnUpdate = new System.Windows.Forms.Button();
            this.SuspendLayout();
            // 
            // cbMarkets
            // 
            this.cbMarkets.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.cbMarkets.FormattingEnabled = true;
            this.cbMarkets.Location = new System.Drawing.Point(16, 16);
            this.cbMarkets.Name = "cbMarkets";
            this.cbMarkets.Size = new System.Drawing.Size(92, 22);
            this.cbMarkets.TabIndex = 4;
            // 
            // btnUpdate
            // 
            this.btnUpdate.Location = new System.Drawing.Point(124, 15);
            this.btnUpdate.Name = "btnUpdate";
            this.btnUpdate.Size = new System.Drawing.Size(75, 23);
            this.btnUpdate.TabIndex = 5;
            this.btnUpdate.Text = "Update";
            this.btnUpdate.UseVisualStyleBackColor = true;
            // 
            // ctlMain
            // 
            this.BackColor = System.Drawing.Color.White;
            this.Controls.Add(this.btnUpdate);
            this.Controls.Add(this.cbMarkets);
            this.Name = "ctlMain";
            this.Size = new System.Drawing.Size(407, 365);
            this.Load += new System.EventHandler(this.ctlMain_Load);
            this.ResumeLayout(false);

		}
		#endregion

		private void ctlMain_Load(object sender, System.EventArgs e)
		{
            // Initialize config
            StreamReader sr = new StreamReader("config.txt");
            while (!sr.EndOfStream)
            {
                switch (sr.ReadLine().Normalize())
                {
                    case "[currency]":
                        currency = sr.ReadLine().Trim();
                        break;
                    case "[nMarkets]":
                        nMarket = int.Parse(sr.ReadLine());
                        PriceBoardServices  = new string[nMarket];
                        MarketNames = new string[nMarket];
                        for (int i = 0; i < nMarket; i++)
                        {
                            MarketNames[i] = sr.ReadLine().Trim();
                            PriceBoardServices[i] = sr.ReadLine().Trim();
                            cbMarkets.Items.Add(MarketNames[i]);
                        }
                        cbMarkets.SelectedIndex = 0;
                        break;
                    case "[favorite]":
                        sListFavoritePath = sr.ReadLine().Trim();
                        break;
                }
            }
            sr.Close();
		}

        private string convertCurrency(string c)
        {
            if (currency == "VN")
                return c.Replace(",","").Replace('.', ',');
            return c.Replace(",", "");
        }
    }
}
